//
//  FoodOrderCell.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2021/9/13.
//  Copyright © 2021 zwb. All rights reserved.
//

import UIKit

import Kingfisher
let ZyaFoodOStatusDic = ["0":"未提交","9":"已提交","1":"已下单","3":"已完成"]
let ZyaFoodOStatusDicDesc = ["全部":"","未提交":"0","已提交":"9","已下单":"1","已完成":"3"]
let ZyaFoodOSColorDic = ["0":UIColor.darkGray,"9":UIColor.orange,"1":UIColor.blue,"3":Theme.primaryColor()]

class ZyaFoodOrderCell: UITableViewCell {
  
    private var lab1: UILabel = {
        var v = UILabel()
        v.numberOfLines = 2
        v.text = "订单号"
        v.font = UIFont.boldSystemFont(ofSize: 15)
        return v
    }()
    private var lab1Con: UILabel = {
        var v = UILabel()
        v.textColor = .darkGray
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
    private var lab2: UILabel = {
        var v = UILabel()
        v.text = "客户"

        v.numberOfLines = 2
        v.font = UIFont.boldSystemFont(ofSize: 15)
        return v
    }()
    private var lab2Con: UILabel = {
        var v = UILabel()
        v.textColor = .darkGray
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
    private var lab3: UILabel = {
        var v = UILabel()
        v.text = "下单日期"

        v.numberOfLines = 2
        v.font = UIFont.boldSystemFont(ofSize: 15)
        return v
    }()
    private var lab3Con: UILabel = {
        var v = UILabel()
        v.textColor = .darkGray
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
    private var right1: UILabel = {
        var v = UILabel()
        v.numberOfLines = 2
        v.font = UIFont.boldSystemFont(ofSize: 15)
        return v
    }()
    private var right2: UILabel = {
        var v = UILabel()
        v.numberOfLines = 2
        v.font = UIFont.boldSystemFont(ofSize: 15)
        return v
    }()
    lazy var bg:UIView = {
        let v = UIView()
        v.backgroundColor = .white
        v.layer.masksToBounds = true
        v.layer.cornerRadius = 6
        return v
    }()
   
 
    var ob:OperateBtnGroup!
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.backgroundColor = .clear
        self.backgroundColor = .clear
    
        self.contentView.addSubview(bg)
       
       
        bg.addSubview(lab1)
        bg.addSubview(lab1Con)

        bg.addSubview(lab2)
        bg.addSubview(lab2Con)

        bg.addSubview(lab3)
        bg.addSubview(lab3Con)
        bg.addSubview(right1)
        bg.addSubview(right2)

       
        
 
        self.makeConstrainsts()
        
    }
 
    func makeConstrainsts() {
        
        bg.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView).offset(5)
            make.right.equalTo(self.contentView).offset(-5)
            make.top.equalTo(self.contentView).offset(5)
            make.bottom.equalTo(self.contentView).offset(-5)
        }
   
        
        lab1.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(5)
            make.top.equalToSuperview().offset(8)
        }
        
        lab2.snp.makeConstraints { (make) in
            make.left.equalTo(lab1)
            make.top.equalTo(lab1.snp.bottom).offset(5)
        }
        
        lab3.snp.makeConstraints { (make) in
            make.left.equalTo(lab1)
            make.top.equalTo(lab2.snp.bottom).offset(8)
        }
    
        lab1Con.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(81)
            make.centerY.equalTo(lab1)
        }
        lab2Con.snp.makeConstraints { (make) in
            make.left.equalTo(lab1Con)
            make.centerY.equalTo(lab2)
        }
        lab3Con.snp.makeConstraints { (make) in
            make.left.equalTo(lab1Con)
            make.centerY.equalTo(lab3)
        }
        right1.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-8)
            make.centerY.equalTo(lab1)
        }
        right2.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-8)
            make.centerY.equalTo(lab3)
        }
        self.ob = OperateBtnGroup(frame: CGRect(x:20,y:0,width:KSGlobal.screenW - 40,height:32),cRadius_group: 15,colors: [.darkGray], titles: [],bWidth_group: 85)
        bg.addSubview(self.ob)
        self.ob.snp.makeConstraints({ (make) in
            make.left.equalTo(lab1)
            make.right.equalTo(bg).offset(-10)
            make.height.equalTo(30)
            make.bottom.equalTo(bg).offset(-8)
        })
        
 
      
        
    }
    
 
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var one = ZyaFoodOrderModel(JSON:["":""])! {
        didSet {
            lab1Con.text = one.sNo.unwrap
            right1.text = ZyaFoodOStatusDic[one.sAuditMark.unwrap]
            right1.textColor = ZyaFoodOSColorDic[one.sAuditMark.unwrap]
            var clientStr = one.sClientNm.unwrap
            if one.sBranchClientNm != "" {
                clientStr += "(\(one.sBranchClientNm.unwrap))"
            }
            lab2Con.text = clientStr
              lab3Con.text = one.sCreateTm.unwrap
            
            if let mm = one.sTotalMoney {
                right2.text = "￥ " + mm.twoZero
            } else {
                right2.text = "￥ 0.00"
            }
            
            if one.sAuditMark == "1" || one.sAuditMark == "3" {
                self.ob.setTitle(["再来一单"])
            } else  if one.sAuditMark == "9" {
                self.ob.setTitle( ["反提交","再来一单"])
            } else {
                self.ob.setTitle(["提交","删除","再来一单"])
            }
            
//            if one.showPaopao {
//                addPaopao()
//            } else {
//                closePaopao()
//            }
        }
    }
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
